#!/bin/bash
#cp build /usr/local/bin/
run1(){
   local nexus="192.168.75.13:30093" 
   #local nexus="ai.internal:30082"
   run2nexus $1 $2 $nexus
}
run2nexus(){
   local dir=$1
   local imageName=$2
   local nexus=$3

   if [ ! -f $dir"Dockerfile" ];then
     echo $dir"Dockerfile does not exists! exit!"
     exit 1
   fi
   echo "docker build $dir -t $nexus/$imageName"
   local v=$(docker build $dir -t $nexus/$imageName)
   echo $v
   if [ $v -ne 0 ];then
     echo "build Failed"
     echo $v
     exit 1
   fi
   docker push $nexus/$imageName
   docker rmi $nexus/$imageName
}
print_user_guide(){
  echo "1 or 2 parameters required for the image name or directory"
  echo "user guide: build ./ image_name:version"
  echo "user guide for the directory now in: build image_name:version"
}
echo "input parameters:" $1 $2
if test -z "$1"
then
  print_user_guide
  exit 1
else
  if test -z "$2"
  then
    print_user_guide
    run1 "./" $1
  else
    run1 $1 $2
  fi
fi 


